package DXQclient;

import java.awt.Color;

import javax.swing.JOptionPane;

import HGbet.HGbethttp;
import P8.StoneAgeClient;


public class DXQClientThread extends Thread{

	public long sleepTime = 30*1000;
	DXQclientManager dxqClientManager = null;
	
	boolean start = false;
	boolean loginNow = false;

	public DXQClientThread(){
		
		
	}
	public void setSleepTime(int sec){
		//sleepTime = sec * 1000;
	}
	
	public void setStart(boolean start) {
		this.start = start;
	}
	
	public void setLoginImmediately(boolean loginNow) {
		this.loginNow = loginNow;
	}
	
	@Override
    public void run() {
		
		StoneAgeClient.betAccountsListWindow.setstatusLabeltext(StoneAgeClient.hgbet.getaccount() + ":在线");
		StoneAgeClient.betAccountsListWindow.setstatusLabelcolor(Color.BLACK);
		

		try{
			
			int time = 0;		
			while(true){
				try{

					time++;
					
					if((time > 200 && StoneAgeClient.blogintohg == true )){
						boolean b = StoneAgeClient.hgbet.checkAccountonline();
						
						
						
						
						if(b){
							time = 0;
							//StoneAgeClient.betAccountsListWindow.setLoginSuccess(dxqClientManager, true);
							
							StoneAgeClient.betAccountsListWindow.setstatusLabeltext(StoneAgeClient.hgbet.getaccount() + ":在线");
							StoneAgeClient.betAccountsListWindow.setstatusLabelcolor(Color.BLACK);
							
							System.out.println("获取成功");
							
						}else{
							
							
							
							System.out.println("DXQClientThread: need relogin");
							
							
							
							int res = StoneAgeClient.hgbet.login();
							
							if(res == 1){
								
								time = 0;
								System.out.println("重新登录成功");
								

								
							}else if(res == 2){
								
								time = 0;
								
								StoneAgeClient.betAccountsListWindow.setstatusLabeltext(StoneAgeClient.hgbet.getaccount() + ":离线");
								StoneAgeClient.betAccountsListWindow.setstatusLabelcolor(Color.red);
								
								
								
							}else if(res == 3){
								StoneAgeClient.betAccountsListWindow.setstatusLabeltext(StoneAgeClient.hgbet.getaccount() + ":账号异常");
								StoneAgeClient.betAccountsListWindow.setstatusLabelcolor(Color.red);
							}
							
							//StoneAgeClient.betAccountsListWindow.setLoginSuccess(dxqClientManager, res == 1 ? true : false);
							
							loginNow = false;
						}
					}
					
					Thread.sleep(2*1000);
					
					
				}catch(Exception e){
					e.printStackTrace();
				}
				

			}
			


		}catch(Exception e){
			e.printStackTrace();
		}	
	}
	
}
